<template>
	<view class="login">
		<view class="t1">
			<image :src="imgUrl+'1.png'" mode="widthFix"></image>
		</view>
		<view class="title">欢迎登录 东哥小程序</view>
		
		<button class="button" open-type="getUserInfo" @getuserinfo="getUserInfo">一键授权登录</button>
	</view>
</template>

<script>

	export default {
		data() {
			return {
				tips: '',
				imgUrl: this.imgUrl,
				seconds: 60,
				id:""
				
			}
		},
		computed: {

		}, 
		onLoad() {},
		onShow() {
			this.$a.GetOpenToken()

		},
		methods: {
			getUserInfo(){
				console.log(8888)
				uni.getUserInfo({
				  provider: 'weixin',
				  complete: (infoRes)=> {
					this.$store.commit('saveuserImg',infoRes.userInfo.avatarUrl)
					console.log('用户昵称为：' + infoRes.userInfo.nickName);
					console.log('用户昵称为：' + infoRes.userInfo.avatarUrl);
					uni.login({
						provider: 'weixin',
						success:(loginRes)=> {
							let code = loginRes.code
							console.log(loginRes)
							this.$http.wxLogin({
								code:loginRes.code,
								appid:this.wxappid,
								scene:""
							}).then(res=>{
								if(res.code==0){
									// this.goTo("/pages/commer/login?id="+res.id);
									// return
									// uni.setStorageSync('u_token',res.data.access_token)
									let u_token = uni.getStorageSync('u_token')
									if(res.isBind&&u_token){
										uni.setStorageSync("isLogin",true);
										this.goTo("/pages/index/index?page=my");
									}else{
										this.goTo("/pages/commer/login?id="+res.id);
									}
								}else{
									uni.showToast({
										title:"授权失败"
									})
								}
							})
						}
					});
				  },
				  fail: (res) => {
				  	
				  }
				});
			}
		}
	}
</script>



<style lang="scss" scoped>
	.title{
		font-size: 40rpx;
		 font-weight: bold;
	}
	.button{font-size: 26rpx;}
	.login {
		text-align: center;
		margin-top: 200upx;

		.t1 {
			image {
				width: 380upx;
				height: 100upx;
			}
		}

		.t2 {
			display: flex;
			align-items: center;
			justify-content: center;
			margin-top: 40upx;
			font-size: 34upx;
			font-weight: 400;
			margin-bottom: 70upx;
			font-size: 34upx;
			font-weight: 400;
			color: #999999;

			view {
				margin: 0 50upx;
				padding-bottom: 6upx;
			}

			.acitve {
				font-size: 34upx;
				font-weight: 500;
				color: #1E7166;
				border-bottom: 2px solid #1E7166;
			}
		}

		.t3 {
			width: 660upx;
			margin: 0 auto;
			background: #FFFFFF;
			border-radius: 10upx;
			padding: 40upx 25upx;
			text-align: left;

			>view {
				display: flex;
				border-bottom: 1px solid #F8F8F8;
				padding-bottom: 40upx;
				justify-content: space-between;
				align-items: center;

				>view {
					display: flex;
					align-items: center;
				}

				.getCode {
					font-size: 24upx;
					display: inline-block;
					width: 160upx;
					text-align: center;
					font-weight: 400;
					color: #BFB49B;
					border-left: 1px solid #ccc;

				}
			}

			>view:last-child {
				padding-bottom: 0;
				margin-top: 40upx;
				border-bottom: 0;
			}

			image {
				width: 40upx;
				height: 40upx;
				margin-right: 16upx;
			}
		}

		.b2 {
			width: 660rpx;
			height: 80upx;
			line-height: 80upx;
			margin: 60upx auto 0;
			background: linear-gradient(270deg, #01AD65 0%, #01AD65 65%, #01AD65 100%);
			border-radius: 100upx;
			font-size: 32upx;
			font-weight: 400;
			color: #F8F7F7;
		}

		.t4 {
			margin-top: 27upx;
			font-size: 20upx;
			font-weight: 400;
			color: #888888;

			text {
				color: #BFB49B;
			}
		}
	}
</style>
